import unittest,time

from selenium.webdriver import Keys
from selenium.webdriver.common.by import By
from selenium import webdriver

class A3mall(unittest.TestCase):
    # TestFixture 测试固件
    def setUp(self) -> None:
        self.driver=webdriver.Edge()
        self.driver.get('http://10.59.9.14:7003/')
        self.driver.maximize_window()

    def tearDown(self) -> None:
        time.sleep(2)
        self.driver.quit()
    # 测试用例

    def test_A3mall_01_login(self):
        # 登录
        self.driver.find_element(By.XPATH,'/html/body/div[1]/div/div[2]/ul/li[1]/a').click()
        time.sleep(3)
        # 断言1：断言文本：会员登陆
        dy1=self.driver.find_element(By.XPATH,'/html/body/div[4]/div/div[1]/div[1]/span[1]').text
        print("文本断言1，会员登陆:",dy1)
        time.sleep(3)
        # 用户名  密码
        self.driver.find_element(By.NAME,'username').send_keys("13811033962")
        time.sleep(3)
        self.driver.find_element(By.NAME,'password').send_keys("123456")
        time.sleep(8)
        # 登录按钮
        self.driver.find_element(By.XPATH, '//*[@id="theForm"]/div[5]/a').click()
        time.sleep(5)
        # 断言2：断言文本：欢迎回来，13811033962
        dy2 = self.driver.find_element(By.XPATH, '/html/body/div[1]/div/div[2]/ul/li[1]/a').text
        print("文本断言2，欢迎回来，13811033962:",dy2)
        time.sleep(2)
        # 断言3：断言文本：账户余额：¥ 988389770.25  中的 988389770.25
        dy3 = self.driver.find_element(By.XPATH, '/html/body/div[5]/div[2]/div[1]/div[2]/div[2]/ul/li[4]').text
        dy31=dy3.replace('¥ ','')
        print("文本断言3，账户余额:",dy31)
        time.sleep(2)

    def test_A3mall_02_search(self):
        # 调用登录成功用例
        self.test_A3mall_01_login()
        # 点击首页
        self.driver.find_element(By.XPATH,'/html/body/div[3]/div[2]/ul/li[1]/a').click()
        # 输入框输入凤冠
        search=self.driver.find_element(By.XPATH,'//*[@id="searchForm"]/div[1]/input')
        search.send_keys('凤冠')
        search.send_keys(Keys.ENTER)
        # 断言4：搜索凤冠 搜索列表：搜索结果
        dy4=self.driver.find_element(By.XPATH,'/html/body/div[4]/a[2]').text
        print("文本断言4，搜索结果:",dy4)
        # 选择凤冠
        self.driver.find_element(By.XPATH,'/html/body/div[5]/div[2]/div[2]/div[1]/ul/li/div[1]/span/a/img').click()
        # 断言5：商品详情：断言文本：
        dy5=self.driver.find_element(By.XPATH,'//*[@id="goodsForm"]/div/div[2]').text
        print("文本断言5，明孝端皇后九龙九凤冠:",dy5)
        # 断言6 商品价格 10.00
        dy6=self.driver.find_element(By.ID,'sell-price-box').text
        print("文本断言6，10.00：",dy6)
        # 购物车数量 清除1  输入2
        nums=self.driver.find_element(By.ID,'store_nums')
        nums.clear()
        nums.send_keys(2)
        dy7=nums.text
        print("文本断言7，数量：",dy7)

        # 点击立即购买
        self.driver.find_element(By.XPATH,'//*[@id="buy-cart"]').click()
        # 断言文本： 断言确认订单
        dy8 = self.driver.find_element(By.XPATH, '/html/body/div[4]/div[1]/a[2]')
        print("文本断言8，确认订单:", dy8)
        # 确认收获地址
        self.driver.find_element(By.CLASS_NAME,'radio-select-btn').click()
        # 选择支付方式
        self.driver.find_element(By.XPATH,'//*[@id="theForm"]/div[3]/div[2]/div[1]/label/input').click()
        # 下一步 支付订单成功
        self.driver.find_element(By.CSS_SELECTOR,'.ask-btn').click()







    # TestSuite 测试套件
    # TestRunner 测试执行